package com.y.architecture.login;

import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.y.architecture.R;
import com.y.architecture.base.NeedInitViewHelper;


/**
 * Created by youjingjing on 2017/7/19.
 */

public class LoginHelper extends NeedInitViewHelper<ILoginContact.ILoginView> implements ILoginContact.ILoginPresent {

    public LoginHelper(ILoginContact.ILoginView mBaseView) {
        super(mBaseView);
    }

    public LoginHelper(ILoginContact.ILoginView mBaseView, View mRoot) {
        super(mBaseView, mRoot);
    }

    @Override
    public boolean validateInfo(EditText view) {
        String s = mBaseView.getInputText(view);
        String emptyInfo = "1";
        String errorInfo = "2";
        int i = view.getId();
        switch (view.getId()){
            case R.id.login_edit_name:
                emptyInfo = "用户名不能为空";
                errorInfo = "用户不存在";
                break;
            case R.id.login_edit_psw:
                emptyInfo = "密码不能为空";
                errorInfo = "密码不正确";
                break;
            case R.id.login_edit_host:
                emptyInfo = "host不能为空";
                errorInfo = "host不正确";
                break;
            case R.id.login_edit_port:
                emptyInfo = "端口号不能为空";
                errorInfo = "端口号不正确";
                break;
        }
        if (TextUtils.isEmpty(s) ) {
            mBaseView.errorWarning(view,emptyInfo);
            return false;
        }else if(!isAccountValid(s)){
            mBaseView.errorWarning(view,errorInfo);
            return false;
        }
        return true;
    }

    @Override
    public EditText getEditName() {
        EditText editText = getView(R.id.login_edit_name);
        return editText;
    }

    @Override
    public EditText getEditKey() {
        EditText editText = getView(R.id.login_edit_psw);
        return editText;
    }

    @Override
    public EditText getEditPort() {
        EditText editText = getView(R.id.login_edit_port);
        return editText;
    }

    @Override
    public EditText getEditHost() {
        EditText editText = getView(R.id.login_edit_host);
        return editText;
    }

    @Override
    public Button getButton() {
       Button button = getView(R.id.login_btn_commit);
       return button;
    }

    public boolean isNumValid(String port) {
        return true;
    }

    public boolean isAccountValid(String account) {
        return true;
    }

    public boolean isPasswordValid(String password) {
        return true;
    }

}

